import java.io.File;
import java.io.PrintWriter;
import java.util.Arrays;

public class Demo {
	/* Command line specific */
	static String PRUN = "prun -np 1 -t 00:15:00 java -Xmx22G ScheduleAll";
	static int numberOfNodes = 1;

	/* Globals that make up block path */
	static String DIR = "../predictions";
	static String ALG = "AUS";
	static String DAT = "val";
	static int K = 1;
	static String BLOCK_PATH;

	/* End of command line globals */
	static int BEGIN = 0;
	static int END = 1000990;
	static int THREADS = 16;

	public static void main(String[] args) {
		printHeader();
		printBody();
		checkForWesselOnly(args);
	}

	private static void printHeader() {
		file = new File("go.sh");

		try {
			pw = new PrintWriter(file);
		} catch (Exception e) {
			e.printStackTrace();
		}

		println("#!/bin/bash\n");
		println("#$ -l h_rt=00:15:00");
		println("#$ -N WEDNESS");
		println("#$ -cwd\n");

//		println("dos2unix *.java");
//		println("rm *.class");
//		println("javac *.java");
	}

	private static void printBody() {
		int b = 1000990 / numberOfNodes;

		for (int begin = 0; begin < 1000990; begin += b) {
			int end = begin + b;
			if (end > 1000990) {
				end = 1000990;
			}

			print(PRUN + " ");
			print(ALG + " " + DAT + " " + K + " ");
			print(begin + " " + end + " " + THREADS);
			println(" < /dev/null &");
		}

		pw.close();
	}

	static void print(String string) {
		pw.print(string);
		System.out.print(string);
	}

	static void println(String string) {
		pw.println(string);
		System.out.println(string);
	}

	static void checkForWesselOnly(String[] args) {
		if (args.length > 0) {
			if (args[0].contains("wes")) {
				System.out.println(Arrays.toString(args));

				args = new String[] { ALG, DAT, K + "", BEGIN + "", END + "",
						"4" };

				ScheduleAll.main(args);
			}
		}
	}

	/* Printer globals */
	static File file;
	static PrintWriter pw;
}
